class Solution3 {
    public int numDistinct(String s, String t) {
          int m = t.length() ;
          int n = s.length() ;
          int[][] dp = new int[m+1][n+1];
          s = " "+s ;
          t = " "+t ;
          char[] sArr = s.toCharArray();
          char[] tArr = t.toCharArray() ;
           for(int j=0 ; j <= n ; j ++){
            dp[0][j] = 1 ;
           }
          for(int i=1 ;i <= m ; i ++){
            for(int j=1 ; j <= n ; j ++){
                 dp[i][j] = dp[i][j-1]+(sArr[j]==tArr[i]?dp[i-1][j-1]:0);
            }
          } 
         return dp[m][n] ;
    }
}